package org.fastmvc.factory;

import java.util.HashMap;
import java.util.Map;

import org.fastmvc.exception.BeanStoreException;
import org.fastmvc.exception.BeansException;
import org.fastmvc.exception.NoSuchBeanException;
import org.fastmvc.factory.support.BeanRegistry;

/**
 * <类描述>
 *
 * @author tangch
 * @date 2017年11月07日 17:25
 */
public class BeanContext implements BeanFactory,BeanRegistry {

	protected Map<Class<?> ,Object> beans = new HashMap<Class<?>,Object>();

	@Override
	public <T> void registerBean(Class<T> clazz, T object) throws BeanStoreException {
		beans.put(clazz,object);
	}

	@Override
	public <T> void removeBean(Class<T> clazz) throws NoSuchBeanException {
		beans.remove(clazz);
	}

	@Override
	public <T> T getBean(Class<T> clazz) throws BeansException {
		return (T) beans.get(clazz);
	}

	@Override
	public <T> boolean containsBean(Class<T> clazz) {
		return beans.containsKey(clazz);
	}

	@Override
	public <T> boolean isSingleton(Class<T> clazz) throws NoSuchBeanException {
		return true;
	}

	@Override
	public <T> boolean isPrototype(Class<T> clazz) throws NoSuchBeanException {
		return false;
	}
}
